{% extends 'fwMapBase.html' %}

{% block script %}
    {{ super() }}
    <script>
        $(function () {
            // 加载api 渲染input框的value属性
            var position_id = document.location.pathname.split('/')[3];
            var changeid = document.location.pathname.split('/')[4];

            $(window).on('load', function () {
                $.ajax({
                    url: "{{ url_for('fwmap.FwmapEdit') }}",
                    type: "GET",
                    async: false,
                    data: {"changeid": changeid},
                    success: function (data) {
                        if (data.code == "10000") {
                            var xxx = data.data[0];
                            $("#serialnumber").attr('value', xxx.serialnumber);
                            $("#protocols option[value='" + xxx.protocols + "']").attr('selected', 'selected');
                            $("#inaddress").val(xxx.inaddress).trigger('change');
                            $("#inport").attr('value', xxx.inport);
                            $("#outaddress").val(xxx.outaddress).trigger('change');
                            $("#outport").attr('value', xxx.outport);
                            $("#sequenceid").attr('value', xxx.sequenceid);
                        }
                    }
                })
            });

            $("#butn").on('click', function () {
                var inputdic = mapDic();
                inputdic["position_id"] = position_id;
                $.ajax({
                    url: "{{ url_for('fwmap.FwmapEdit') }}",
                    type: "put",
                    contentType: "application/json",
                    data: JSON.stringify(inputdic),
                    success: function (data) {
                        if (data.code == 10000) {
                            swal({
                                title: "修改成功！",
                                text: "2秒后自动返回首页。",
                                timer: 2000,
                                showConfirmButton: false
                            }, function () {
                                setInterval(function () {
                                    window.open("/fwmap/" + position_id, "_self")
                                }, 1000)
                            });
                        }
                    }
                })

            })
        });


    </script>
{% endblock %}

